﻿function addTicket(scheduleID) {
    if (scheduleID > 0)
        price = ($('input[name=' + scheduleID + ']:checked').val());
    else{
        alert("Please select train time for booking");
        return;
        }

    if (typeof (price) !== 'undefined' && price != null) {
        // take the data and post it via json
        $.post("/CheckOut/AddTicket", { TrainsId: scheduleID, Price: price }, function (data) {
            // get the result and do some magic with it
            var message = data.Message;
            $("#resultMessage").html(message);
        });
    }
    else {
        alert("Please select train time for booking");
        return;
    }
}

function removeTicket(scheduleID) {
    if (confirm("Are you sure you want to remove ticket?")) {
        if (scheduleID > 0) {
            // take the data and post it via json
            $.post("/CheckOut/RemoveTicket", { TrainsId: scheduleID, Price: 0 }, function (data) {
                // get the result and do some magic with it
                var message = data.Message;
                $("#resultMessage").html(message);
            });
        }
        else {
            alert("Please select train");
        } 
    }
}

function deleteTicket(url) {
    // get the result and do some magic with it// get the result and do some magic with it// get the result and do some magic with it// get the result and do some magic with it// get the result and do some magic with it
    // get the result and do some magic with it
 if (confirm("Are you sure you want to remove ticket?")) {
    var url = "/CheckOut/RemoveTicket/"+url;
    $(location).attr('href', url);
}
}

function selectDate(scheduleID) {
    if (scheduleID > 0) {
        // take the data and post it via json
        $.post("/CheckOut/SetDate", { TrainsId: scheduleID, Date: $('#' + scheduleID + '').val() }, function (data) {
            // get the result and do some magic with it
            var message = data.Message;
            var fare = data.Fare;
            var totalTicket = data.TotalTicket;
            var totalFare = data.TotalFare;
            var taxs = data.Taxs;
            var total = data.Total;

            $('#Date' + scheduleID + '').html(message);
            $('#Fare' + scheduleID + '').html(fare);
            $('#Total' + scheduleID + '').html(totalTicket);
            $('#Taxs').html(taxs);
            $('#TotalFare').html(totalFare);
            $('#Total').html(total);
        });
    }
}

function selectAdults(scheduleID) {
    if (scheduleID > 0) {
        // take the data and post it via json
        $.post("/CheckOut/SetAdults", { TrainsId: scheduleID, Adults: $('#Adults' + scheduleID + '').val() }, function (data) {
            // get the result and do some magic with it
            var total = data.Total;
            var message = data.Message;
            var totalFare = data.TotalFare;
            var taxs = data.Taxs;
            

            $('#Total').html(total);
            $('#Total' + scheduleID + '').html(message);
            $('#Taxs').html(taxs);
            $('#TotalFare').html(totalFare);
           

        });
    }
}

function selectChildren(scheduleID) {
    if (scheduleID > 0) {
        // take the data and post it via json
        $.post("/CheckOut/SetChildren", { TrainsId: scheduleID, Children: $('#Children' + scheduleID + '').val() }, function (data) {
            // get the result and do some magic with it
            var message = data.Message;
            var totalFare = data.TotalFare;
            var taxs = data.Taxs;
            var total = data.Total;

            $('#Total' + scheduleID + '').html(message);
            $('#Taxs').html(taxs);
            $('#TotalFare').html(totalFare);
            $('#Total').html(total);
        });
    }
}

function selectAudience(ID) {
    
        // take the data and post it via json
    $.post("/Fireworks_DaNang/SetTickets", { ticketType: ID + "_" + $('#' + ID + '').val() }, function (data) {
            // get the result and do some magic with it

            var total = data.Total;

            $('#TotalPrice').html(total);
        });

}

function btnSearch() {
    var url = "/train/route/train-from-" + $('#Departure').val() + "-to-" + $('#Arrival').val()+"";
        $(location).attr('href', url);
}

function fillSelectArr() {
    $('#Arrival').children().remove().end();
    jQuery("#Departure option").each(function () {
        if (jQuery(this).val() != $('#Departure').val()) {
            $('#Arrival').append('<option value=' + jQuery(this).val() + '>' + jQuery(this).text() + '</option>');
        }
    });
}

 